package com.wjpeng.wms.web.controller;

import com.wjpeng.wms.domain.Permission;
import com.wjpeng.wms.query.QueryObject;
import com.wjpeng.wms.service.IDepartmentService;
import com.wjpeng.wms.service.IPermissionService;
import com.wjpeng.wms.util.JSONResult;
import com.wjpeng.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("list")
    @RequiredPermission("权限列表")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        model.addAttribute("result",permissionService.result(qo));

        return "permission/list";
    }

    @RequestMapping("delete")
    @ResponseBody
    @RequiredPermission("权限删除")
    public Object delete(Long id) throws  Exception{
         permissionService.delete(id);
        return new JSONResult();//象征性返回
    }


    @RequestMapping("reload")
    @RequiredPermission("权限加载")
    @ResponseBody
    public Object reload(){
        permissionService.reload();//加载数据
        return new JSONResult();
    }


}
